import type { CommentVo } from "@/interface/project";
import request from "@/utils/request";

const mock = "https://m1.apifoxmock.com/m1/7176471-6900810-default";

// 评论接口定义
export interface Comment {
  id: string;
  recordId: string;
  userId: string;
  userName: string;
  avatar?: string;
  content: string;
  createTime: string;
  updateTime?: string;
  parentId?: string; // 父评论ID，用于回复
  replies?: Comment[]; // 子评论
}

// 评论查询参数
export interface CommentSearchRequest {
  recordId: string;
  pageNo: number;
  pageSize: number;
}

// 分页结果接口
export interface PageResultComment {
  result: Comment[];
  total: number;
  pageNo: number;
  pageSize: number;
}

// 获取评论列表
export const getComments = (params: CommentSearchRequest) => {
  return request<PageResultComment>({
    url: `${mock}/record/comment/list`,
    method: "post",
    data: params,
  });
};

// 添加评论
export const addComment = (data: {
  recordId: string;
  content: string;
  parentId?: string;
}) => {
  return request<CommentVo>({
    url: `${mock}/record/comment/add`,
    method: "post",
    data,
  });
};

// 删除评论
export const deleteComment = (commentId: string) => {
  return request({
    url: `${mock}/record/comment/${commentId}`,
    method: "delete",
  });
};

// 更新评论
export const updateComment = (commentId: string, content: string) => {
  return request<Comment>({
    url: `${mock}/record/comment/${commentId}`,
    method: "put",
    data: { content },
  });
};
